package com.zhang.servlet;

import com.zhang.pojo.ManBean;
import com.zhang.service.IManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Controller
public class ToUpdateServlet extends HttpServlet {
    @Autowired
    private IManService manService;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf8");

        String id = req.getParameter("upId");
        ManBean manBean = manService.findById(Integer.parseInt(id));
        StringBuffer buffer = new StringBuffer();
        buffer.append(" <form action=\"http://localhost:8083/update\" method=\"post\">");
        buffer.append("姓名: "+manBean.getName()+"<br>");
        buffer.append("生日: <input name='birthday' type=\"text\" placeholder='"+manBean.getBirthday()+"'><br>");
        buffer.append("<input type=\"text\" hidden name=\"id\" value='"+manBean.getId()+"'>");
        buffer.append("<input type=\"submit\" value=\"提交\">");
        buffer.append("</form>");

        resp.getWriter().println(buffer);
    }

}
